resync with upstream sources.
authorJonathan Blandford <jrb@gnome.org>
Tue, 20 Jan 2004 18:07:07 +0000 (18:07 +0000)
committerJonathan Blandford <jrb@src.gnome.org>
Tue, 20 Jan 2004 18:07:07 +0000 (18:07 +0000)
Tue Jan 20 13:07:04 2004  Jonathan Blandford  <jrb@gnome.org>

        * xdgmime.c: resync with upstream sources.

gtk/xdgmime/ChangeLog
gtk/xdgmime/xdgmime.c
gtk/xdgmime/xdgmime.h
gtk/xdgmime/xdgmimeglob.c
gtk/xdgmime/xdgmimeglob.h
gtk/xdgmime/xdgmimeint.c
gtk/xdgmime/xdgmimeint.h
gtk/xdgmime/xdgmimemagic.c
gtk/xdgmime/xdgmimemagic.h

index 77fc6cec7b266b062acc98b05c5292aa0d1ceb55..58f5c6ead45ca9f6c59a0daa33d3bae1ec2913d6 100644 (file)
@@ -1,3 +1,7 @@
+Tue Jan 20 13:07:04 2004  Jonathan Blandford  <jrb@gnome.org>
+
+       * xdgmime.c: resync with upstream sources.
+
 Fri Oct 24 16:54:57 2003  Owen Taylor  <otaylor@redhat.com>
 
        * Makefile.am (libxdgmime_la_SOURCES): Add .h files to 
index d6c90a9e9a05f94400e05574a07b6b661c46e824..44bc754139a2cff9f12b2829691b2bafda8d2540 100644 (file)
 #include <sys/types.h>
 #include <unistd.h>
 
-XdgGlobHash *global_hash = NULL;
-XdgMimeMagic *global_magic = NULL;
-
+static int initted = 0;
+static XdgGlobHash *global_hash = NULL;
+static XdgMimeMagic *global_magic = NULL;
+const char *xdg_mime_type_unknown = "application/octet-stream";
 
 static void
 _xdg_mime_init_from_directory (const char *directory)
@@ -60,8 +61,6 @@ _xdg_mime_init_from_directory (const char *directory)
 static void
 xdg_mime_init (void)
 {
-  static int initted = 0;
-
   if (initted == 0)
     {
       const char *xdg_data_home;
@@ -122,8 +121,9 @@ xdg_mime_init (void)
            len = end_ptr - ptr;
          else
            len = end_ptr - ptr + 1;
-         dir = malloc (len);
+         dir = malloc (len + 1);
          strncpy (dir, ptr, len);
+         dir[len] = '\0';
          _xdg_mime_init_from_directory (dir);
          free (dir);
 
@@ -234,3 +234,19 @@ xdg_mime_is_valid_mime_type (const char *mime_type)
    */
   return _xdg_utf8_validate (mime_type);
 }
+
+void
+xdg_mime_shutdown (void)
+{
+  /* FIXME: Need to make this (and the whole library) thread safe */
+  if (initted)
+    {
+      _xdg_glob_hash_free (global_hash);
+      global_hash = NULL;
+
+      _xdg_mime_magic_free (global_magic);
+      global_magic = NULL;
+
+      initted = 0;
+    }
+}
index ae0c45d292430bef60d1a0000b155b66b7a3bc4b..f67b7b17e434c74252cd67e6984213705656075a 100644 (file)
 extern "C" {
 #endif /* __cplusplus */
 
-#define XDG_MIME_TYPE_UNKNOWN "application/octet-stream"
+extern const char *xdg_mime_type_unknown;
+#define XDG_MIME_TYPE_UNKNOWN xdg_mime_type_unknown
 
 #ifdef XDG_PREFIX
 #define XDG_ENTRY(func) _XDG_ENTRY2(XDG_PREFIX,func)
 #define _XDG_ENTRY2(prefix,func) _XDG_ENTRY3(prefix,func)
 #define _XDG_ENTRY3(prefix,func) prefix##_##func
+#endif
 
+  
+#ifdef XDG_PREFIX
 #define xdg_mime_get_mime_type_for_data       XDG_ENTRY(get_mime_type_for_data)
 #define xdg_mime_get_mime_type_for_file       XDG_ENTRY(get_mime_type_for_file)
 #define xdg_mime_get_mime_type_from_file_name XDG_ENTRY(get_mime_type_from_file_name)
 #define xdg_mime_is_valid_mime_type           XDG_ENTRY(is_valid_mime_type)
+#define xdg_mime_type_unknown                 XDG_ENTRY(type_unknown)
 #endif
 
 const char *xdg_mime_get_mime_type_for_data       (const void *data,
@@ -53,6 +58,7 @@ const char *xdg_mime_get_mime_type_for_data       (const void *data,
 const char *xdg_mime_get_mime_type_for_file       (const char *file_name);
 const char *xdg_mime_get_mime_type_from_file_name (const char *file_name);
 int         xdg_mime_is_valid_mime_type           (const char *mime_type);
+void        xdg_mime_shutdown                     (void);
 
 #ifdef __cplusplus
 }
index 83ec7372f35c6f9e74b25bb82b1f343c8bb350ca..b8b4d706a4a03baf1271cf1602312c5a5c7b1a2b 100644 (file)
@@ -1,5 +1,5 @@
 /* -*- mode: C; c-file-style: "gnu" -*- */
-/* xdgmime.c: Private file.  Datastructure for storing the globs.
+/* xdgmimeglob.c: Private file.  Datastructure for storing the globs.
  *
  * More info can be found at http://www.freedesktop.org/standards/
  *
@@ -8,7 +8,7 @@
  *
  * Licensed under the Academic Free License version 2.0
  * Or under the following terms:
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
@@ -78,13 +78,27 @@ _xdg_glob_list_new (void)
   return new_element;
 }
 
-#if 0
+/* Frees glob_list and all of it's children */
 static void
 _xdg_glob_list_free (XdgGlobList *glob_list)
 {
-  free (glob_list);
+  XdgGlobList *ptr, *next;
+
+  ptr = glob_list;
+
+  while (ptr != NULL)
+    {
+      next = ptr->next;
+
+      if (ptr->data)
+       free ((void *) ptr->data);
+      if (ptr->mime_type)
+       free ((void *) ptr->mime_type);
+      free (ptr);
+
+      ptr = next;
+    }
 }
-#endif
 
 static XdgGlobList *
 _xdg_glob_list_append (XdgGlobList *glob_list,
@@ -139,14 +153,6 @@ _xdg_glob_hash_node_new (void)
   return glob_hash_node;
 }
 
-#if 0
-static void
-_xdg_glob_hash_node_free (XdgGlobHashNode *glob_hash_node)
-{
-  free (glob_hash_node);
-}
-#endif
-
 void
 _xdg_glob_hash_node_dump (XdgGlobHashNode *glob_hash_node,
                          int depth)
@@ -346,12 +352,12 @@ _xdg_glob_hash_free_nodes (XdgGlobHashNode *node)
 void
 _xdg_glob_hash_free (XdgGlobHash *glob_hash)
 {
+  _xdg_glob_list_free (glob_hash->literal_list);
+  _xdg_glob_list_free (glob_hash->full_list);
   _xdg_glob_hash_free_nodes (glob_hash->simple_node);
   free (glob_hash);
 }
 
-
-
 XdgGlobType
 _xdg_glob_determine_type (const char *glob)
 {
index 72ea10166d6a9497c1b816579ad4a61fecb0a462..4b31f27f150962ae8df70a24219627b8ebfbfbbe 100644 (file)
@@ -1,14 +1,14 @@
 /* -*- mode: C; c-file-style: "gnu" -*- */
-/* xdgmime.h: Private file.  Datastructure for storing the globs.
+/* xdgmimeglob.h: Private file.  Datastructure for storing the globs.
  *
  * More info can be found at http://www.freedesktop.org/standards/
- * 
+ *
  * Copyright (C) 2003  Red Hat, Inc.
  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
  *
  * Licensed under the Academic Free License version 2.0
  * Or under the following terms:
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
@@ -28,6 +28,7 @@
 #ifndef __XDG_MIME_GLOB_H__
 #define __XDG_MIME_GLOB_H__
 
+#include "xdgmime.h"
 
 typedef struct XdgGlobHash XdgGlobHash;
 
@@ -38,6 +39,16 @@ typedef enum
   XDG_GLOB_FULL,    /* x*.[ch] */
 } XdgGlobType;
 
+  
+#ifdef XDG_PREFIX
+#define _xdg_mime_glob_read_from_file         XDG_ENTRY(glob_read_from_file)
+#define _xdg_glob_hash_new                    XDG_ENTRY(hash_new)
+#define _xdg_glob_hash_free                   XDG_ENTRY(hash_free)
+#define _xdg_glob_hash_lookup_file_name       XDG_ENTRY(hash_lookup_file_name)
+#define _xdg_glob_hash_append_glob            XDG_ENTRY(hash_append_glob)
+#define _xdg_glob_determine_type              XDG_ENTRY(determine_type)
+#define _xdg_glob_hash_dump                   XDG_ENTRY(hash_dump)
+#endif
 
 void         _xdg_mime_glob_read_from_file   (XdgGlobHash *glob_hash,
                                              const char  *file_name);
index faf79879d401615a40bae8a4599db50a47371c77..8dde2e0c296550f3fbc3476be4342c3888a97810 100644 (file)
@@ -2,13 +2,13 @@
 /* xdgmimeint.c: Internal defines and functions.
  *
  * More info can be found at http://www.freedesktop.org/standards/
- * 
+ *
  * Copyright (C) 2003  Red Hat, Inc.
  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
  *
  * Licensed under the Academic Free License version 2.0
  * Or under the following terms:
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
@@ -37,7 +37,7 @@
 #define        TRUE    (!FALSE)
 #endif
 
-const unsigned char utf8_skip_data[256] = {
+const unsigned char _xdg_utf8_skip_data[256] = {
   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
@@ -48,7 +48,7 @@ const unsigned char utf8_skip_data[256] = {
   3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1
 };
 
-const char * const utf8_skip = utf8_skip_data;
+const char * const _xdg_utf8_skip = _xdg_utf8_skip_data;
 
 
 
@@ -65,33 +65,33 @@ _xdg_utf8_to_ucs4(const char *source)
     {
       int bytelength = 0;
       xdg_unichar_t result;
-      if ( ! *source & 0x40 )
+      if ( ! (*source & 0x40) )
        {
          ucs32 = *source;
        }
       else
        {
-         if ( ! *source & 0x20 )
+         if ( ! (*source & 0x20) )
            {
              result = *source++ & 0x1F;
              bytelength = 2;
            }
-         else if ( ! *source & 0x10 )
+         else if ( ! (*source & 0x10) )
            {
              result = *source++ & 0x0F;
              bytelength = 3;
            }
-         else if ( ! *source & 0x08 )
+         else if ( ! (*source & 0x08) )
            {
              result = *source++ & 0x07;
              bytelength = 4;
            }
-         else if ( ! *source & 0x04 )
+         else if ( ! (*source & 0x04) )
            {
              result = *source++ & 0x03;
              bytelength = 5;
            }
-         else if ( ! *source & 0x02 )
+         else if ( ! (*source & 0x02) )
            {
              result = *source++ & 0x01;
              bytelength = 6;
index f8bf18c4cb32f7b1fa9bbeef49c9e6bd127764d7..8f6bafa41a757d8bf4278a1be84580d4be4ce0e8 100644 (file)
@@ -2,13 +2,13 @@
 /* xdgmimeint.h: Internal defines and functions.
  *
  * More info can be found at http://www.freedesktop.org/standards/
- * 
+ *
  * Copyright (C) 2003  Red Hat, Inc.
  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
  *
  * Licensed under the Academic Free License version 2.0
  * Or under the following terms:
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
 #ifndef __XDG_MIME_INT_H__
 #define __XDG_MIME_INT_H__
 
+#include "xdgmime.h"
+
 /* FIXME: Should be configure check */
 typedef unsigned int   xdg_unichar_t;
 typedef unsigned char  xdg_uchar8_t;
 typedef unsigned short xdg_uint16_t;
 typedef unsigned int   xdg_uint32_t;
 
+#ifdef XDG_PREFIX
+#define _xdg_utf8_skip   XDG_ENTRY(utf8_skip)
+#define _xdg_utf8_to_ucs4   XDG_ENTRY(utf8_to_ucs4)
+#define _xdg_ucs4_to_upper   XDG_ENTRY(ucs4_to_upper)
+#define _xdg_utf8_validate   XDG_ENTRY(utf8_validate)
+#define _xdg_get_base_name   XDG_ENTRY(get_ase_name)
+#endif
 
 #define SWAP_BE16_TO_LE16(val) (xdg_uint16_t)(((xdg_uint16_t)(val) << 8)|((xdg_uint16_t)(val) >> 8))
 
@@ -43,9 +52,9 @@ typedef unsigned int   xdg_uint32_t;
                                              (((xdg_uint32_t)(val) & 0x000000FFU) << 24))
 /* UTF-8 utils
  */
-const char *const utf8_skip;
-#define _xdg_utf8_next_char(p) (char *)((p) + utf8_skip[*(unsigned char *)(p)])
-#define _xdg_utf8_char_size(p) (int) (utf8_skip[*(unsigned char *)(p)])
+const char *const _xdg_utf8_skip;
+#define _xdg_utf8_next_char(p) (char *)((p) + _xdg_utf8_skip[*(unsigned char *)(p)])
+#define _xdg_utf8_char_size(p) (int) (_xdg_utf8_skip[*(unsigned char *)(p)])
 
 xdg_unichar_t  _xdg_utf8_to_ucs4  (const char    *source);
 xdg_unichar_t  _xdg_ucs4_to_upper (xdg_unichar_t  source);
index 7124f96814308985fc4d5604a29cfee77833f972..da1f22b27d34baf8479837abf550697b8ceac791 100644 (file)
@@ -1,15 +1,14 @@
-
 /* -*- mode: C; c-file-style: "gnu" -*- */
-/* xdgmimemagic.: Private file.  Datastructure for storing magic.
+/* xdgmimemagic.: Private file.  Datastructure for storing magic files.
  *
  * More info can be found at http://www.freedesktop.org/standards/
- * 
+ *
  * Copyright (C) 2003  Red Hat, Inc.
  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
  *
  * Licensed under the Academic Free License version 2.0
  * Or under the following terms:
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * Boston, MA 02111-1307, USA.
  */
 
+#include <assert.h>
 #include "xdgmimemagic.h"
 #include "xdgmimeint.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
@@ -111,17 +110,6 @@ _xdg_mime_magic_matchlet_new (void)
   return matchlet;
 }
 
-void
-_xdg_mime_magic_match_free (XdgMimeMagicMatch *mime_magic_match)
-{
-  if (mime_magic_match)
-    {
-      if (mime_magic_match->mime_type)
-       free ((char *)mime_magic_match->mime_type);
-      free (mime_magic_match);
-    }
-}
-
 
 void
 _xdg_mime_magic_matchlet_free (XdgMimeMagicMatchlet *mime_magic_matchlet)
@@ -139,6 +127,27 @@ _xdg_mime_magic_matchlet_free (XdgMimeMagicMatchlet *mime_magic_matchlet)
 }
 
 
+/* Frees mime_magic_match and the remainder of its list
+ */
+void
+_xdg_mime_magic_match_free (XdgMimeMagicMatch *mime_magic_match)
+{
+  XdgMimeMagicMatch *ptr, *next;
+
+  ptr = mime_magic_match;
+  while (ptr)
+    {
+      next = ptr->next;
+
+      if (ptr->mime_type)
+       free ((void *) ptr->mime_type);
+      if (ptr->matchlet)
+       _xdg_mime_magic_matchlet_free (ptr->matchlet);
+      free (ptr);
+
+      ptr = next;
+    }
+}
 
 /* Reads in a hunk of data until a newline character or a '\000' is hit.  The
  * returned string is null terminated, and doesn't include the newline.
@@ -173,7 +182,7 @@ _xdg_mime_magic_read_to_newline (FILE *magic_file,
          retval = realloc (retval, len);
        }
     }
-    
+
   retval[pos] = '\000';
   return retval;
 }
@@ -189,7 +198,7 @@ _xdg_mime_magic_read_a_number (FILE *magic_file,
   char number_string[MAX_NUMBER_SIZE];
   int pos = 0;
   int c;
-  int retval = -1;
+  long retval = -1;
 
   while (TRUE)
     {
@@ -213,9 +222,10 @@ _xdg_mime_magic_read_a_number (FILE *magic_file,
   if (pos > 0)
     {
       number_string[pos] = '\000';
+      errno = 0;
       retval = strtol (number_string, NULL, 10);
-      if ((retval == LONG_MIN || retval == LONG_MAX) &&
-         (errno == ERANGE))
+
+      if ((retval < INT_MIN) || (retval > INT_MAX) || (errno != 0))
        return -1;
     }
 
@@ -233,8 +243,8 @@ _xdg_mime_magic_parse_header (FILE *magic_file, XdgMimeMagicMatch *match)
   char *end_ptr;
   int end_of_file = 0;
 
-  assert (magic_file);
-  assert (match);
+  assert (magic_file != NULL);
+  assert (match != NULL);
 
   c = fgetc (magic_file);
   if (c == EOF)
@@ -303,7 +313,7 @@ _xdg_mime_magic_parse_magic_line (FILE              *magic_file,
   int indent = 0;
   int bytes_read;
 
-  assert (magic_file);
+  assert (magic_file != NULL);
 
   /* Sniff the buffer to make sure it's a valid line */
   c = fgetc (magic_file);
@@ -334,7 +344,7 @@ _xdg_mime_magic_parse_magic_line (FILE              *magic_file,
 
   if (c != '>')
     return XDG_MIME_MAGIC_ERROR;
-    
+
   matchlet = _xdg_mime_magic_matchlet_new ();
   matchlet->indent = indent;
   matchlet->offset = _xdg_mime_magic_read_a_number (magic_file, &end_of_file);
@@ -489,7 +499,7 @@ _xdg_mime_magic_parse_magic_line (FILE              *magic_file,
       matchlet->next = match->matchlet;
       match->matchlet = matchlet;
 
-      
+
       return XDG_MIME_MAGIC_MAGIC;
     }
 
@@ -506,7 +516,7 @@ _xdg_mime_magic_matchlet_compare_to_data (XdgMimeMagicMatchlet *matchlet,
                                          size_t                len)
 {
   int i, j;
-      
+
   for (i = matchlet->offset; i <= matchlet->offset + matchlet->range_length; i++)
     {
       int valid_matchlet = TRUE;
@@ -594,7 +604,7 @@ _xdg_mime_magic_insert_match (XdgMimeMagic      *mime_magic,
       return;
     }
 
-  if (match->priority < mime_magic->match_list->priority)
+  if (match->priority > mime_magic->match_list->priority)
     {
       match->next = mime_magic->match_list;
       mime_magic->match_list = match;
@@ -641,7 +651,7 @@ _xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic,
                             size_t        len)
 {
   XdgMimeMagicMatch *match;
-  
+
   for (match = mime_magic->match_list; match; match = match->next)
     {
       if (_xdg_mime_magic_match_compare_to_data (match, data, len))
@@ -649,7 +659,7 @@ _xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic,
          return match->mime_type;
        }
     }
-      
+
   return NULL;
 }
 
@@ -658,7 +668,7 @@ _xdg_mime_update_mime_magic_extents (XdgMimeMagic *mime_magic)
 {
   XdgMimeMagicMatch *match;
   int max_extent = 0;
-  
+
   for (match = mime_magic->match_list; match; match = match->next)
     {
       XdgMimeMagicMatchlet *matchlet;
index 50f179ae60b7f5629aa60fa9a8648e1e723d35e4..dea0a3c040589695362607831a0818f9266ebea7 100644 (file)
@@ -1,14 +1,14 @@
 /* -*- mode: C; c-file-style: "gnu" -*- */
-/* xdgmimemagic.h: Private file.  Datastructure for storing the globs.
+/* xdgmimemagic.h: Private file.  Datastructure for storing the magic files.
  *
  * More info can be found at http://www.freedesktop.org/standards/
- * 
+ *
  * Copyright (C) 2003  Red Hat, Inc.
  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
  *
  * Licensed under the Academic Free License version 2.0
  * Or under the following terms:
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
 #define __XDG_MIME_MAGIC_H__
 
 #include <unistd.h>
-
+#include "xdgmime.h"
 typedef struct XdgMimeMagic XdgMimeMagic;
 
+#ifdef XDG_PREFIX
+#define _xdg_mime_glob_read_from_file             XDG_ENTRY(glob_read_from_file)
+#define _xdg_mime_magic_new                       XDG_ENTRY(magic_new)
+#define _xdg_mime_magic_read_from_file            XDG_ENTRY(magic_read_from_file)
+#define _xdg_mime_magic_free                      XDG_ENTRY(magic_free)
+#define _xdg_mime_magic_get_buffer_extents        XDG_ENTRY(magic_get_buffer_extents)
+#define _xdg_mime_magic_lookup_data               XDG_ENTRY(magic_lookup_data)
+#endif
+
+
 XdgMimeMagic *_xdg_mime_magic_new                (void);
 void          _xdg_mime_magic_read_from_file     (XdgMimeMagic *mime_magic,
                                                  const char   *file_name);